{include file="public/nheader"}
<div class="layui-fluid layui-bg-white">
    <form action="{:url()}" class="layui-form layui-form-fixed">

        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>品牌
            </label>
            <div class="layui-input-block">
                <select name="agentid">
                    <option value="">请选品牌</option>
                    {foreach $agent as $v}
                    <option value="{$v.id}" {if !empty($row.agentid) && $row.agentid==$v.id}selected{/if}>{$v.nickname}
                    </option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>收款类型
            </label>
            <div class="layui-input-block">
                <input lay-filter="type" type="radio" name="type" value="1" title="微信" {if !empty($row.type) &&
                    $row.type==1}checked{/if}>
                <input lay-filter="type" type="radio" name="type" value="2" title="支付宝" {if !empty($row.type) &&
                    $row.type==2}checked{/if}>
                <input lay-filter="type" type="radio" name="type" value="3" title="银行卡" {if !empty($row.type) &&
                    $row.type==3}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item banks" {if $row.type !=3}style="display: none;" {/if}>
            <label class="layui-form-label">
                <font color="red">* </font>开户行
            </label>
            <div class="layui-input-block">
                <input type="text" name="bank" autocomplete="off" class="layui-input" value="{$row.bank|default=''}"
                    placeholder="请填写">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>收款账号名
            </label>
            <div class="layui-input-block">
                <input type="text" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input"
                    value="{$row.name|default=''}" placeholder="请填写">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                收款账号
            </label>
            <div class="layui-input-block">
                <input type="text" name="number" autocomplete="off" class="layui-input" value="{$row.number|default=''}"
                    placeholder="请填写">
            </div>
        </div>
        <div class="layui-form-item skms" {if $row.type==3}style="display: none;" {/if}>
            <label class="layui-form-label">
                收款码
            </label>
            <div class="layui-input-block">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-upload-list">
                    <input type="hidden" value="{$row.images|default=''}" name="images" id="covers">
                    <img class="layui-upload-img" id="demo1" src="{$row.images|default=''}"
                        style="width: 200px;height: auto;">
                </div>
            </div>
        </div>
        <div class="layui-footer layui-form-item layui-center ">
            <input type="hidden" value="{$row['id']|default='0'}" name="id" />
            <button class="layui-btn" lay-filter="submitIframe" type="button" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
        </div>
    </form>
</div>
{include file="public/nfooter"}
<script>
    layui.use(['form', 'layer', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;
        form.on('radio(type)', function (data) {
            var type = data.value;
            if (type == 3) {
                $('.banks').show();
                $('.skms').hide();

            } else {
                $('.banks').hide();
                $('.skms').show();
            }
            form.render();
        });
        //图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/base/upload_img'
            , accept: 'images'
            , before: function (obj) {
                layer.load(); //上传loading
            }, done: function (res) {
                //如果上传失败
                if (res.code == 1) {
                    layer.closeAll('loading'); //关闭loading
                    return layer.msg('图片上传失败，请重试');
                }
                if (res.code == 200) {
                    //上传成功
                    $('#demo1').attr('src', res.url); //图片链接（base64）
                    $('#covers').val(res.url);
                    layer.closeAll('loading'); //关闭loading
                    return layer.msg('图片上传成功');
                }
            }
            , error: function () {
                layer.closeAll('loading'); //关闭loading
                return layer.msg(res.msg);
            }
        });
    });
</script>